<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="/global/jsp-header.jsp"%>
<c:set var="groupQueryVisable" value="${d:accessUri('/group/group-query.do',pageContext.request) }"></c:set>
<c:set var="groupAddVisable" value="${d:accessUri('/group/group-add.do',pageContext.request) }"></c:set>
<c:set var="groupDeleteVisable" value="${d:accessUri('/group/group-delete.do',pageContext.request) }"></c:set>
<c:set var="groupEditVisable" value="${d:accessUri('/group/group-edit.do',pageContext.request) }"></c:set>
<!DOCTYPE HTML>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html">
		<title>组别管理</title>
		<%@ include file="/global/html-header.jsp"%>
		<script type="text/javascript">
	$(function() {
		$(".myform").idealforms();
		<c:if test="${groupQueryVisable}">
		$("#myform").submit();
		</c:if>
		common.validator("myform");
		common.initDialog("message-dialog");
		common.initDelDialogMsg("确定要删除此组别？");
		
		<c:if test="${groupAddVisable}">
		$("#addGroup").on("click",function(){
			$("#addorupdate-dialog").wijdialog({ width: 700, height: 440, contentUrl: '/group/group-addorupdate.do?operationType=insert', autoOpen: true,modal : true,title:"新增组别" });
		});
		</c:if>
		
		$("#delete-dialog").wijdialog({
            autoOpen: false,
            resizable: false,
            height: 200,
            width: 320,
            modal: true,
            buttons: {
                "确定": function () {
                	if(!$("#delete-dialog").attr("operaterId")){
                		return false;
                	}
                	<c:if test="${groupDeleteVisable}">
                	var delGroupId=$("#delete-dialog").attr("operaterId");
                	$.ajax({   
                		type: "POST",  
                		url: "/group/group-delete.do",  
                		data: ({"group.groupId":delGroupId}), 
                		success: function(msg){    
                			if(msg=="success"){
                				$("#msgcontent").html("组别删除成功！");
                				$("#queryResultIframe").contents().find("tr[groupId='"+delGroupId+"']'").remove();
                			}else if(msg=="workervested"){
                				$("#msgcontent").html("组别下还有员工，请先移出这些员工！");
                			}else{
                				$("#msgcontent").html("组别删除失败！");
                			}
                			common.tipWithAutoClose("message-dialog");
                		} 
                	});
                    $(this).wijdialog("close");
                    </c:if>
                },
                "取消": function () {
                    $(this).wijdialog("close");
                }
            }
        });
	});
	//删除部门窗口弹出
	function deleteDivOpen(groupId){
		$('#delete-dialog').wijdialog('open');
		$('#delete-dialog').attr("operaterId",groupId);
	}
	
	<c:if test="${groupDeleteVisable}">
	function editGroupTip(msg){
		$("#msgcontent").html(msg);
		common.tipWithAutoClose("message-dialog");
	}
	
	function editDivOpen(groupId){
		$("#addorupdate-dialog").wijdialog({ width: 700, height: 440, contentUrl: '/group/group-addorupdate.do?operationType=update&group.groupId='+groupId, autoOpen: true,modal : true,title:"编辑组别" });
	}
	</c:if>
	function closeDialog(){
		$("#addorupdate-dialog").wijdialog('close');
	}
</script>
	</head>
	<body>
		<div class="container ">
			<div class="content">
				<form action="/group/group-query.do" name="myform" class="myform"
					id="myform" target="queryResultIframe" method="post">
					<div>
						<label>
							组别编号:
						</label>
						<input type="text" size="40" name="group.groupId" class="digits" />
					</div>
					<div>
						<label>
							组别名称:
						</label>
						<input type="text" size="40" name="group.groupName" />
					</div>
					<div>
						<label>是否可用:</label>
						<select name="group.disabled">
							<option value="">请选择</option>
							<option value="1">可用</option>
							<option value="0">不可用</option>
						</select>
					</div>
					<div>
						<label>
							&nbsp;
						</label>
						<c:if test="${groupQueryVisable}">
						<input type="submit" value="提交" />
						<input type="reset" value="重置" />
						</c:if>
						<c:if test="${groupAddVisable}">
						<input type="reset" id="addGroup" value="新增" />
						<em class="ideal-button" style="visibility:hidden;"></em>
						</c:if>
					</div>
				</form>
			</div>
			<div class="content hide" id="queryResult">
				<iframe class="queryResultIframe" name="queryResultIframe"
					id="queryResultIframe" src="about:blank" style="width: 97%;"
					frameborder="0" scrolling="no"></iframe>
			</div>
		</div>
		<%@ include file="/global/common-dialog.jsp" %>
	</body>
</html>